package com.glodon.paas.account.dao.mysql;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;

import com.glodon.paas.account.dao.TokenDao;
import com.glodon.paas.account.dao.domain.OAuthTokenEntity;
import com.glodon.paas.account.dao.mapper.OAuthTokenEntityMapper;

public class TokenDaoMysqlImpl implements TokenDao {
	@Autowired
	private OAuthTokenEntityMapper oAuthTokenEntityMapper;

	@Override
	public String insert(OAuthTokenEntity entity) {
		oAuthTokenEntityMapper.insertSelective(entity);
		return entity.getValue();
	}

	@Override
	public OAuthTokenEntity get(String id) {
		return oAuthTokenEntityMapper.selectByPrimaryKey(id);
	}

	@Override
	public int delete(String id) {
		return oAuthTokenEntityMapper.deleteByPrimaryKey(id);
	}

	@Override
	public List<OAuthTokenEntity> getAccessTokens(String authId) {
		return oAuthTokenEntityMapper.selectAccessTokens(authId, true);
	}

}
